package cn.zhouchao.basic.dto;

import cn.zhouchao.basic.util.MD5Utils;
import cn.zhouchao.basic.util.StrUtils;
import cn.zhouchao.user.domain.User;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class WechatBinderDto {
    @NotBlank(message = "电话号码不能为空")
    private String phone;
    @NotBlank(message = "短信验证码不能为空")
    private String verifyCode;
    @NotBlank(message = "token不能为空")
    private String accessToken;
    @NotBlank(message = "openId不能为空")
    private String openId;

    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        String pw = MD5Utils.encrypByMd5(salt + 1);//盐值加密（新绑定这里默认密码为1，需要发送短信告知用户密码为一）
        return User
                .builder()
                .username(this.phone)
                .phone(this.phone)
                .salt(salt)
                .password(pw)
                .state(1)
                .createtime(new Date())
                .build();
    }

}
